﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GsnHelper;
using PetaPoco;
namespace ZhongheCms.Models
{
    public partial class GswTblBusInfo
    {
        [ResultColumn]
        public List<GswViewBusBook>  BusBooks { get; set; }
        [ResultColumn]
        public List<GswTblBaseInfo> BaseInfos { get; set; }
        [ResultColumn]
        public List<GswTblJobInfo> JobInfos { get; set; }
        [ResultColumn]
        public List<GswTblContent> Notices { get; set; }
        [ResultColumn]
        public List<GswTblContent> PartNews { get; set; }
        public static List<GswTblBusInfo> GetBusInfos(string sdate,string edate,string keywords,int cusid)
        {
            var sql = "select * from GswTblBusInfo where ParentId=" + cusid;
            int flag = 0;
            if (InputValid.IsDate(sdate))
            {
                flag = 1;
                sql += " and StartDate>='" + sdate + "'";
            }
            if (InputValid.IsDate(edate))
            {
                flag = 1;
                sql += " and StartDate<='" + edate + "'";
            }
            if (!string.IsNullOrEmpty(keywords))
            {
                flag = 1;
                sql += " and (EndPlace like '%" + keywords + "%' or RouteLine like '%" + keywords + "%')";
            }
            if (flag == 0)
                sql += " and StartDate>='" + DateTime.Today.AddDays(-7).ToShortDateString() + "'";
            sql += " order by StartDate desc";
            var qry = Fetch(sql);
            return qry;
        }
    }
}